<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_bufferAnalyst1"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.text_bufferAnalyst1"></h5></div>
    <div class='panel-body content'>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_bufferAnalyst" onclick="bufferAnalystProcess()"/>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_removeResult" onclick="removeResult()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var map, baseLayer, resultLayer, vectorLayer,
        points = [new SuperMap.Geometry.Point(4933.319287022352, -3337.3849141502124),
            new SuperMap.Geometry.Point(4960.9674060199022, -3349.3316322355736),
            new SuperMap.Geometry.Point(5006.0235999418364, -3358.8890067038628),
            new SuperMap.Geometry.Point(5075.3145648369318, -3378.0037556404409),
            new SuperMap.Geometry.Point(5305.19551436013, -3376.9669111768926)],
        roadLine = new SuperMap.Geometry.LineString(points),
        styleLine = {
            strokeColor: "blue",
            strokeWidth: 3,
            strokeLinecap: "round",
            strokeDashstyle: "solid"
        },
        styleRegion = {
            strokeColor: "#304DBE",
            strokeWidth: 2,
            pointerEvents: "visiblePainted",
            fillColor: "#304DBE",
            fillOpacity: 0.4
        },
        url1 = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
        url2 = host + "/iserver/services/spatialanalyst-changchun/restjsr/spatialanalyst";

    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })], units: "m"
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        map.allOverlays = true;
        baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("Changchun", url1, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        baseLayer.events.on({"layerInitialized": addLayer});
        resultLayer = new SuperMap.Layer.Vector("缓冲区分析结果");
        vectorLayer = new SuperMap.Layer.Vector("vectorLine");

        var featureLine = new SuperMap.Feature.Vector();
        featureLine.geometry = roadLine;
        featureLine.style = styleLine;
        vectorLayer.addFeatures(featureLine);
    }

    function addLayer() {
        map.addLayers([baseLayer, resultLayer, vectorLayer]);
        map.setCenter(new SuperMap.LonLat(5105, -3375), 4);
    }

    function bufferAnalystProcess() {
        widgets.alert.clearAlert();
        resultLayer.removeAllFeatures();
        var bufferServiceByDatasets = new SuperMap.REST.BufferAnalystService(url2),
            bufferDistance = new SuperMap.REST.BufferDistance({
                value: 10
            }),
            bufferSetting = new SuperMap.REST.BufferSetting({
                endType: SuperMap.REST.BufferEndType.ROUND,
                leftDistance: bufferDistance,
                rightDistance: bufferDistance,
                semicircleLineSegment: 10
            }),
            filterParameter = new SuperMap.REST.FilterParameter({
                attributeFilter: "NAME='团结路'"
            }),
            dsBufferAnalystParameters = new SuperMap.REST.DatasetBufferAnalystParameters({
                dataset: "RoadLine2@Changchun",
                filterQueryParameter: filterParameter,
                bufferSetting: bufferSetting
            });
        bufferServiceByDatasets.events.on({
            "processCompleted": bufferAnalystCompleted,
            "processFailed": bufferAnalystFailed
        });
        bufferServiceByDatasets.processAsync(dsBufferAnalystParameters);
    }

    function bufferAnalystCompleted(args) {
        resultLayer.addFeatures(args.result.recordset.features);
    }

    function bufferAnalystFailed(args) {
        widgets.alert.showAlert(args.error.errorMsg,false);
    }

    function removeResult() {
        widgets.alert.clearAlert();
        resultLayer.removeAllFeatures();
    }

</script>

</body>
</html>